import {
  PrimaryGeneratedColumn,
  Column,
  OneToOne,
  ManyToOne,
  JoinColumn,
  CreateDateColumn
} from 'typeorm'
import { EntityModel } from '@midwayjs/orm'
import { Attachment } from './attachment'
import { Department } from './department'

@EntityModel('template')
export class Template {

  @PrimaryGeneratedColumn()
  id: number;

  // 模板所属部门，默认为上传者所属部门，或可选择为其部门子部门
  @ManyToOne(() => Department, { nullable: false })
  @JoinColumn({ name: 'department_id' })
  department: Department;

  @OneToOne(() => Attachment)
  @JoinColumn({ name: 'attachment_id' })
  attachment: Attachment;

  @Column({
    type: 'jsonb',
    default: [],
    comment: '上传后自动识别 docx 文档中的书签，用作插入签名'
  })
  bookmarks: string[];

  @CreateDateColumn({
    comment: '创建时间'
  })
  create_at: Date;
}